# 智能客服系统 API 测试脚本
Write-Host "=== 智能客服系统 API 测试 ===" -ForegroundColor Green

$baseUrl = "http://localhost:5035"

# 测试健康检查
Write-Host "`n1. 测试健康检查..." -ForegroundColor Yellow
try {
    $response = Invoke-RestMethod -Uri "$baseUrl/health" -Method Get
    Write-Host "✓ 健康检查成功: $($response.status)" -ForegroundColor Green
    Write-Host "  服务: $($response.service)" -ForegroundColor Cyan
    Write-Host "  版本: $($response.version)" -ForegroundColor Cyan
} catch {
    Write-Host "✗ 健康检查失败: $($_.Exception.Message)" -ForegroundColor Red
}

# 测试智能对话
Write-Host "`n2. 测试智能对话..." -ForegroundColor Yellow
$chatRequest = @{
    userId = "test_user_001"
    sessionId = "test_session_001"
    message = "查询设备A的当前产量"
} | ConvertTo-Json

try {
    $response = Invoke-RestMethod -Uri "$baseUrl/api/IntelligentCustomerService/chat" -Method Post -Body $chatRequest -ContentType "application/json"
    Write-Host "✓ 智能对话成功" -ForegroundColor Green
    Write-Host "  回复内容: $($response.content)" -ForegroundColor Cyan
    Write-Host "  回复类型: $($response.type)" -ForegroundColor Cyan
    Write-Host "  建议操作数量: $($response.suggestedActions.Count)" -ForegroundColor Cyan
} catch {
    Write-Host "✗ 智能对话失败: $($_.Exception.Message)" -ForegroundColor Red
}

# 测试获取对话历史
Write-Host "`n3. 测试获取对话历史..." -ForegroundColor Yellow
try {
    $response = Invoke-RestMethod -Uri "$baseUrl/api/IntelligentCustomerService/history/test_session_001?limit=5" -Method Get
    Write-Host "✓ 获取对话历史成功" -ForegroundColor Green
    Write-Host "  历史记录数量: $($response.Count)" -ForegroundColor Cyan
    if ($response.Count -gt 0) {
        Write-Host "  最新消息: $($response[0].userInput)" -ForegroundColor Cyan
    }
} catch {
    Write-Host "✗ 获取对话历史失败: $($_.Exception.Message)" -ForegroundColor Red
}

# 测试评价功能
Write-Host "`n4. 测试评价功能..." -ForegroundColor Yellow
$rateRequest = @{
    sessionId = "test_session_001"
    messageId = "test_message_001"
    rating = 5
    feedback = "回答很准确，很有帮助"
} | ConvertTo-Json

try {
    $response = Invoke-RestMethod -Uri "$baseUrl/api/IntelligentCustomerService/rate" -Method Post -Body $rateRequest -ContentType "application/json"
    Write-Host "✓ 评价提交成功: $($response.message)" -ForegroundColor Green
} catch {
    Write-Host "✗ 评价提交失败: $($_.Exception.Message)" -ForegroundColor Red
}

# 测试知识库初始化
Write-Host "`n5. 测试知识库初始化..." -ForegroundColor Yellow
try {
    $response = Invoke-RestMethod -Uri "$baseUrl/api/IntelligentCustomerService/knowledge/initialize" -Method Post
    Write-Host "✓ 知识库初始化成功: $($response.message)" -ForegroundColor Green
} catch {
    Write-Host "✗ 知识库初始化失败: $($_.Exception.Message)" -ForegroundColor Red
}

Write-Host "`n=== API 测试完成 ===" -ForegroundColor Green
Write-Host "访问 Swagger 文档: $baseUrl" -ForegroundColor Cyan 